#! /bin/sh

if [ $# = "0" ] ;then
  tags="3.11.13"
  echo "Usage: $0 x.xx.x [CPU architecture, default x86_64, available: aarch64/armhf/armv7/x86/x86_64/ppc64le/s390x]"
  echo "Usage: $0 3.11.13 [x86_64]"
else
  tags="$1"
fi

if [ $# = "2" ] ;then
  arch="$2"
else
  arch="x86_64"
fi

vers=$(echo ${tags}|cut -d. -f1-2)

echo ${vers}
echo ${tags}

#wget -c https://mirrors.aliyun.com/alpine/v3.11/releases/aarch64/alpine-minirootfs-3.11.13-aarch64.tar.gz
#docker build -t alpine:3.11.13 .

wget -c https://mirrors.aliyun.com/alpine/v${vers}/releases/${arch}/alpine-minirootfs-${tags}-${arch}.tar.gz

echo FROM scratch > Dockerfile
echo ADD alpine-minirootfs-${tags}-${arch}.tar.gz / >> Dockerfile
echo CMD [\"/bin/sh\"] >> Dockerfile
docker build --platform linux/${arch} -t alpine:${tags} .
